//导入相关模块
import {Move} from "../../../gcg/libs/role/body/Move.js";//移动组件
import {Interval} from "../../../gcg/libs/timer/Interval.js";//任务管理器
import {Role} from "../../../gcg/libs/role/role/Role.js";//角色组件
import {Crash} from "../../../gcg/libs/crash/Crash.js";//碰撞组件
import {CompeteConstant} from "../../../gcg/libs/constants/CompeteConstant.js";
import {Foe} from "../../../gcg/libs/foe/foe/Foe.js";
import {Log} from "../../../gcg/libs/log/Log.js";
//对抗常量

//运行多个敌人,敌人自由移动，自由停止

!function () {
    //初始化友军对象
    let roleElement = $('#role');
    let role = new Role();
    role.compete = CompeteConstant.FRIEND;
    role.setNickname();//可选
    role.setTop(roleElement, 250);
    role.setLeft(roleElement, 45);
    role.setDirection(roleElement, 'down');
    role.init(roleElement);


    //初始化敌军对象//可选
    let foe = new Foe();
    let foeClass = 'foe';
    foe.setClass(foeClass);
    foe.compete = CompeteConstant.FOE;
    foe.setStartSit([
        {top:200,left:5},
        {top:160,left:60},
        {top:25,left:250}
        ]);//设置初始位置
    foe.defaultDirection = 'down';
    let foeIdBox = foe.createFoes(3);
    foe.setDescription('这是一个不会动的智障敌人');


    //初始化移动组件
    let move = new Move();



    //初始化碰撞检测组件
    let crash = new Crash();
    crash.init();



    let timeArr = [
        1000,
        40,
        15
    ];
    // 敌军自由移动
    $(foe.getClass()).each(function (a, element) {
        //初始化任务管理器
        let interval = new Interval();
        interval.time = timeArr[a];

        //初始化移动组件
        move.init(element);

        let freeItv = interval.set(function () {
            try{
                //敌军移动
                move.do(element);
                //实时碰撞检测
                crash.detect(roleElement, element, function () {
                    interval.stop(freeItv);
                });

                //边界碰撞检测
                crash.detectBody(element,function () {
                    interval.stop(freeItv);
                });

            }catch (e) {
                Log.log(e);
                interval.stop(freeItv);
            }
        });
    });


}();